<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /*
            构造函数
                1. let obj = {}
                2. obj.__proto__ = Person.prototype
                3. obj = Person.call(obj)
                4. 返回 obj

            prototype json

            
            let p = new Person('test');

            p.prototype -> Person -> Function -> Object

            继承
            this, call, apply
        */
        
        let Animal = function() {

        }
        Animal.sleep = function() {
            console.log(
                this.name + '正在睡觉'
            )
        }
        let Person = function(name) {
            this.name = name || '石兴龙'
        }
        
        // Person.prototype = new Animal()
        // Person.prototype.constructor = Person
        Person.prototype.eat = function () {
            console.log(
                this.name + '正在吃饭'
            )
        }

        for (let key in Animal.prototype) {
            Person.prototype[key] = Animal.prototype[key]
        }
        Person.prototype.constructor = null
        // Person.prototype = {
        //     eat: function() {
        //         console.log(
        //             this.name + '正在吃饭'
        //         )
        //     },
        //     constructor: Person
        // }
        console.log(
            Person.prototype
        )
        let p = new Person('test');
        console.log(
            p.__proto__ === Person.prototype,
            Person.__proto__ === Function.prototype,
        )

    </script>
</body>
</html>